package org.emet.entity.ash;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 骨灰寄存室
 * 
 * @author alex
 * 
 */
@Entity
@Table(name = "t_ash_hall")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AshHall extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String code;
	private String name;
	private List<Frame> frames;

	@Column(nullable = false, unique = true)
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@OneToMany(mappedBy = "ashHall")
	@Cascade( { CascadeType.DELETE, CascadeType.SAVE_UPDATE })
	public List<Frame> getFrames() {
		return frames;
	}

	public void setFrames(List<Frame> frames) {
		this.frames = frames;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(getCode()).append(getId()).append(getName()).hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AshHall == false)
			return false;
		if (this == obj)
			return true;
		AshHall other = (AshHall) obj;
		return new EqualsBuilder().append(getId(), other.getId()).append(getCode(), other.getCode()).append(getName(), other.getName()).isEquals();
	}

}
